#!/bin/bash

. ./cmd.sh ## You'll want to change cmd.sh to something that will work on your system.
           ## This relates to the queue.

. ./path.sh

#for baseDir in exp_pdnn/warm_str_dnn_fbank_new; do
for baseDir in exp_pdnn/warm6_str_dnn_fbank_spk_01; do
echo $baseDir
dnn=$baseDir/dnn.nnet
dir=speaker-sensitivity/$baseDir
data_dir=exp_pdnn/warm_ivec_dnn_fbank_new
mkdir -p $dir
dir=`perl -e '($dir,$pwd)= @ARGV; if($dir!~m:^/:) { $dir = "$pwd/$dir"; } print $dir; ' $dir ${PWD}`
stage=-4

if [ $stage -le -4 ]; then
###################### Create nnets to get hidden activations ########################
echo "Creating intermediate nnets"
#nnet-concat exp/tri4b_pretrain-dbn_dnn/final.feature_transform $dnn $dir/final_full.net
nnet-copy --remove-last-layers=12 $dnn $dir/final_1.nnet
nnet-copy --remove-last-layers=10 $dnn $dir/final_2.nnet
nnet-copy --remove-last-layers=8 $dnn $dir/final_3.nnet
nnet-copy --remove-last-layers=6 $dnn $dir/final_4.nnet
nnet-copy --remove-last-layers=4 $dnn $dir/final_5.nnet
nnet-copy --remove-last-layers=2 $dnn $dir/final_6.nnet
echo "nnet creation successful"
fi




if [ $stage -le -3 ]; then
################### Generate Hidden Activations ####################################

activationDir=$dir/activations/

for layer in $(seq 1 6);do
 h=$activationDir/h$layer
 mkdir -p $h
 echo "The hidden activations will be stored in $h directory"
 for x in MEGJ0 MTDB0 FSAH0 MSTF0 MABC0 FDAW0 MJAE0 MRJB1 MJRK0 MDHS0 MPSW0 MTBC0 MSVS0 MLEL0 FGRW0 FLJA0 FPAB1 MPGR0 FPAF0 FLAC0 MSDB0 FEXM0 MJKR0 MMWS0 MRCG0 MKAH0 MREE0 MTRR0 MZMB0 FDJH0 MMEA0 FSKL0 FKAA0 MWRE0 MILB0 FBLV0 MPRK0 MDJM0 MRSP0 MDLC1; do
# for x in FDNC0 FDTD0 FDXW0 FEAC0 FEAR0 FECD0 FEEH0 FEME0 FETB0 FEXM0 MMWS0 MMWS1 MMXS0 MNET0 MNTW0 MPAR0 MPEB0 MPFU0 MPGH0 MPGR0; do
   grep --no-filename ^$x $data_dir/append_feat.train.*.scp | nnet-forward $dir/final_$layer.nnet  scp:- ark,t:$h/activations_$x.ark
 done
 echo "Dumping activations for training dataset and $layer is completed"
done

#for layer in $(seq 1 5);do
# h=$activationDir/h$layer
# mkdir -p $h
# echo "The hidden activations will be stored in $h directory"
# for x in FDHC0 FELC0 FJLM0 FMGD0 FMLD0 FNLP0 FPAS0 FPKT0 MBPM0 MCMJ0 MDAB0 MGRT0 MJDH0 MJLN0 MJMP0 MKLT0; do
#   grep --no-filename ^$x $baseDir/decode_test/add_feat.is_spk_mode.*.scp | nnet-forward $dir/final_$layer.nnet  scp:- ark,t:$h/activations_$x.ark
# done
# echo "Dumping activations for testing dataset and $layer is completed"
#done

fi

echo "$baseDir is done"
done

